package com.fph.design.service.impl;

import com.fph.design.RedisUtils;
import com.fph.design.matter.EGM;
import com.fph.design.matter.IIR;
import com.fph.design.service.CacheService;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName CacheServiceImpl
 * @Description TODO
 * @Author fph
 * @Date 2024-07-09 17:34
 **/
public class CacheServiceImpl implements CacheService {

    private RedisUtils redisUtils = new RedisUtils();
    private EGM egm = new EGM();
    private IIR iir = new IIR();

    @Override
    public void del(String key, Integer redisType) {
        if(redisType == 1){
            redisUtils.del(key);
        }else if(redisType == 2){
            egm.delete(key);
        }else{
            iir.del(key);
        }
    }

    @Override
    public String get(String key, Integer redisType) {
        String returnStr = "";
        switch (redisType){
            case 1:
                returnStr = redisUtils.get(key);
                break;
            case 2:
                returnStr = egm.gain(key);
                break;
            case 3:
                returnStr = iir.get(key);
                break;
        }
        return returnStr;
    }

    @Override
    public void set(String key, String value, Integer redisType) {
        switch (redisType){
            case 1:
                redisUtils.set(key, value);
                break;
            case 2:
                egm.set(key, value);
                break;
            case 3:
                iir.set(key, value);
                break;
        }
    }

    @Override
    public void set(String key, String value, long timeout, TimeUnit timeUnit, Integer redisType) {
        switch (redisType){
            case 1:
                redisUtils.set(key, value, timeout, timeUnit);
                break;
            case 2:
                egm.setEx(key, value, timeout, timeUnit);
                break;
            case 3:
                iir.setExpire(key, value, timeout, timeUnit);
                break;
        }
    }
}

